// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in routes.js
angular.module('liemallfodder', [
  'ionic',
  'ksSwiper',
  'ngAnimate',
  'toaster'
])
  .run(function ($rootScope, $ionicPlatform, $ionicNavBarDelegate) {
    $ionicPlatform.ready(function () {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);

      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
      }

      $ionicNavBarDelegate.showBackButton(false);
      $rootScope.showLoading = false;
      $rootScope.showBackButton = false;
      $rootScope.BASE_URL = 'http://cms.tieshenmimi.com';
      // $rootScope.BASE_URL = 'http://devcms.tieshenmimi.com'; // test service

      $rootScope.showBackButton = window.location.href.indexOf('home') === -1;
      $rootScope.$on('$stateChangeStart',function(event,next){
        var name = next.name;
        $rootScope.showBackButton = name.indexOf('home') === -1;
        if ($rootScope.showLoading) {
          $rootScope.showLoading = false;
        }
      });

      $rootScope.goBack = function () {
        window.history.back();
      };

      $rootScope.toAbsoluteUrl = function (path) {
        if (path && (path.indexOf('http') == 0 || path.indexOf('https') == 0)) {
          return path;
        }
        return $rootScope.BASE_URL + path;
      };

    });
  })

  .config(function ($stateProvider, $urlRouterProvider, $httpProvider, $ionicConfigProvider) {

    $httpProvider.defaults.withCredentials = true;
    $ionicConfigProvider.backButton.previousTitleText(false).text('').icon('');
    $ionicConfigProvider.views.transition('none');
    $urlRouterProvider.otherwise('/home');
  });
